package com.chainyoung.component_tmperson.ui.activity;


import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chainyoung.common.appcommon.entity.Version;
import com.chainyoung.common.base.BaseActivity;
import com.chainyoung.common.bus.AppManagerEvent;
import com.chainyoung.common.bus.RxBus;
import com.chainyoung.common.constant.LibConstant;
import com.chainyoung.common.di.AppComponent;
import com.chainyoung.common.event.BaseEvent;
import com.chainyoung.common.utils.AppUtils;
import com.chainyoung.common.utils.ToastUtil;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.di.component.DaggerPersonActivityComponent;
import com.chainyoung.component_tmperson.di.module.PersonActivityModule;
import com.chainyoung.component_tmperson.ui.mvp.contract.HelpCenterContract;
import com.chainyoung.component_tmperson.ui.mvp.presenter.HelpCenterPresenter;
import com.chainyoung.router.RouterConstants;
import com.chainyoung.router.RouterUtils;

import org.simple.eventbus.EventBus;

import java.util.TreeMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.chainyoung.common.bus.AppManagerEvent.KILL_ALL;
import static com.chainyoung.common.constant.CommonStringConstants.TRADE_NAME;
import static com.chainyoung.common.constant.CommonStringConstants.TRADE_TYPE;

public class HelpCenterActivity extends BaseActivity<HelpCenterPresenter> implements HelpCenterContract.View {


    @BindView(R2.id.tv_version_code)
    TextView tvVersion;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPersonActivityComponent.builder()
                .appComponent(appComponent)
                .personActivityModule(new PersonActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initUI() {
        setCurrentTitle(R.string.tmperson_help_center);
        tvVersion.setText(AppUtils.getAppVersionName(mContext));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.tmperson_help_center;
    }

    @OnClick(R2.id.tv_about_fiat_currency)
    void aboutFiatCurrency() {
        RouterUtils.getInstance()
                .build(RouterConstants.PATH_ABOUT_FIAT)
                .navigation();

    }

    @OnClick(R2.id.ll_version)
    void checkVersion() {
        mPresenter.checkUpdate();
    }

    @OnClick(R2.id.tv_protocol)
    void checkProtocol() {
        launch(ProtocolActivity.class);
    }


   /* @OnClick(R2.id.tv_login_out)
    void loginOut() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.tmperson_confirm_exit)
                .setPositiveButton(mContext.getString(R.string.confirm), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        RouterUtils.getInstance()
                                .build(RouterConstants.PATH_MAIN_LOGIN)
                                .navigation(mContext);
                        RxBus.getDefault().post(new AppManagerEvent(KILL_ALL, getString(R.string.login_out)));
                        EventBus.getDefault().post(new BaseEvent<>(BaseEvent.EventCode.LOGIN_OUT));
                        dialog.dismiss();
                    }
                })
                .setNegativeButton(mContext.getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

        builder.create();
        builder.show();
    }*/


    @Override
    public void showVersion(final Version data) {
        if (data == null||data.getVersion_code()<=AppUtils.getAppVersionCode(mContext)) {
            ToastUtil.showToast(getString(R.string.tmperson_already_newest_version));
            return;
        } else if (data.getVersion_code() > AppUtils.getAppVersionCode(mContext)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    RouterUtils.getInstance()
                            .build(RouterConstants.PATH_UPDATE)
                            .withParcelable(LibConstant.VERSION, data)
                            .navigation(mContext);
                }
            }, 0);

        }
    }
}
